/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.zimbra.common.mailbox.ContactConstants;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.mailbox.ContactGroup.Member.Type;
/*     */ import com.zimbra.qa.QA.Bug;
/*     */ import com.zimbra.soap.account.message.SearchGalRequest;
/*     */ import com.zimbra.soap.account.message.SearchGalResponse;
/*     */ import com.zimbra.soap.mail.message.CreateContactRequest;
/*     */ import com.zimbra.soap.mail.message.CreateContactResponse;
/*     */ import com.zimbra.soap.mail.message.GetContactsRequest;
/*     */ import com.zimbra.soap.mail.message.GetContactsResponse;
/*     */ import com.zimbra.soap.mail.type.ContactGroupMember;
/*     */ import com.zimbra.soap.mail.type.ContactSpec;
/*     */ import com.zimbra.soap.mail.type.NewContactAttr;
/*     */ import com.zimbra.soap.mail.type.NewContactGroupMember;
/*     */ import com.zimbra.soap.type.Id;
/*     */ import java.util.List;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestContactGroup
/*     */   extends SoapTest
/*     */ {
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   private static Account acct;
/*     */   private static Account memberAcct;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  57 */     provUtil = new SoapProvTestUtil();
/*  58 */     prov = provUtil.getProv();
/*  59 */     domain = provUtil.createDomain(baseDomainName());
/*     */     
/*  61 */     acct = provUtil.createAccount("acct", domain);
/*  62 */     memberAcct = provUtil.createAccount("member-acct", domain);
/*     */     
/*  64 */     GalTestUtil.enableGalSyncAccount(prov, domain.getName());
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup()
/*     */     throws Exception
/*     */   {
/*  71 */     if (acct != null) {
/*  72 */       provUtil.deleteAccount(acct);
/*     */     }
/*     */     
/*  75 */     if (memberAcct != null) {
/*  76 */       provUtil.deleteAccount(memberAcct);
/*     */     }
/*     */     
/*  79 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   @Test
/*     */   @QA.Bug(bug={70558})
/*     */   public void createAndGetContactGroup() throws Exception {
/*  85 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  90 */     SearchGalRequest searchGalReq = new SearchGalRequest();
/*  91 */     searchGalReq.setName(memberAcct.getName());
/*  92 */     SearchGalResponse searchGalResp = (SearchGalResponse)invokeJaxb(transport, searchGalReq);
/*  93 */     List<com.zimbra.soap.account.type.ContactInfo> entries = searchGalResp.getContacts();
/*     */     
/*  95 */     Assert.assertEquals(1L, entries.size());
/*  96 */     com.zimbra.soap.account.type.ContactInfo galEntry = (com.zimbra.soap.account.type.ContactInfo)entries.get(0);
/*  97 */     String galMemberRef = galEntry.getReference();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 102 */     NewContactGroupMember contactGroupMemer = NewContactGroupMember.createForTypeAndValue(ContactGroup.Member.Type.GAL_REF.getSoapEncoded(), galMemberRef);
/*     */     
/* 104 */     NewContactAttr contactAttr = new NewContactAttr(ContactConstants.A_type);
/* 105 */     contactAttr.setValue("group");
/*     */     
/* 107 */     ContactSpec contactSpec = new ContactSpec();
/* 108 */     contactSpec.addAttr(contactAttr);
/* 109 */     contactSpec.addContactGroupMember(contactGroupMemer);
/*     */     
/* 111 */     CreateContactRequest createContactReq = new CreateContactRequest(contactSpec);
/* 112 */     CreateContactResponse createContactResp = (CreateContactResponse)invokeJaxb(transport, createContactReq);
/*     */     
/* 114 */     String contactGroupId = createContactResp.getContact().getId();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 119 */     GetContactsRequest getContactsReq = new GetContactsRequest();
/* 120 */     getContactsReq.addContact(new Id(contactGroupId));
/* 121 */     getContactsReq.setDerefGroupMember(Boolean.TRUE);
/* 122 */     GetContactsResponse getContactsResp = (GetContactsResponse)invokeJaxb(transport, getContactsReq, SoapProtocol.SoapJS);
/*     */     
/* 124 */     List<com.zimbra.soap.mail.type.ContactInfo> contacts = getContactsResp.getContacts();
/* 125 */     Assert.assertEquals(1L, contacts.size());
/* 126 */     com.zimbra.soap.mail.type.ContactInfo contact = (com.zimbra.soap.mail.type.ContactInfo)contacts.get(0);
/* 127 */     List<ContactGroupMember> members = contact.getContactGroupMembers();
/* 128 */     Assert.assertEquals(1L, members.size());
/*     */     
/* 130 */     ContactGroupMember member = (ContactGroupMember)members.get(0);
/* 131 */     String memberType = member.getType();
/* 132 */     String memberValue = member.getValue();
/* 133 */     Assert.assertEquals(ContactGroup.Member.Type.GAL_REF.getSoapEncoded(), memberType);
/* 134 */     Assert.assertEquals(galMemberRef, memberValue);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestContactGroup.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */